package tcp

import (
	"fmt"
	"net"
	"io/ioutil"
)

func checkError(err error) {
	if err != nil {
		fmt.Println("Fatal error:", err.Error())
	}
}

func TcpClient() {
	service := "localhost:7777"
	tcpAddr, err := net.ResolveTCPAddr("tcp4", service)
	checkError(err)
	conn, err := net.DialTCP("tcp", nil, tcpAddr)
	checkError(err)
	_, err = conn.Write([]byte("HEAD / HTTP/1.0\r\n\r\n"))
	checkError(err)

	result, err := ioutil.ReadAll(conn)
	checkError(err)
	fmt.Print("result:")
	fmt.Println(string(string(result)))

/*	var buf [512]byte
	result,err := conn.Read(buf[0:])
	checkError(err)
	fmt.Print("result:")
	fmt.Println(string(string(buf[0:result])))*/
}
